"use strict";

const fs = require("fs");
const path = require("path");

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    /**
     * Add seed commands here.
     *
     * Example:
     * await queryInterface.bulkInsert('People', [{
     *   name: 'John Doe',
     *   isBetaMember: false
     * }], {});
     */

    // Read the JSON data
    const jsonData = fs.readFileSync(path.resolve("./data", "user_origin.json"));
    const rowdata = JSON.parse(jsonData);
    const data = rowdata.map((item) => {
      return {
        ...item,
        createdAt: new Date(),
        updatedAt: new Date(),
      };
    })

    // Insert data into the database using the model
    await queryInterface.bulkInsert("Gg_users", data, {});
  },

  async down(queryInterface, Sequelize) {
    /**
     * Add commands to revert seed here.
     *
     * Example:
     * await queryInterface.bulkDelete('People', null, {});
     */

    await queryInterface.bulkDelete('Gg_users', null, {});
  },
};
